/*
 * Digital Audio Mobile - A multi track studio for Windows Mobile
 * Copyright (C) 2008 David Olsson
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "Composition.h"
#include "CompositionInfoControl.h"
#include "DamDialog.h"
#include "Device.h"
#include "MusicTime.h"

CompositionInfoControl::CompositionInfoControl(DamDialog *parent, const Composition *composition) throw(): Control(parent, 0, parent->height() - 24, parent->width(), 24), m_hBpm(0), m_hSignature(0), m_hPos(0), m_composition(composition) {
    TCHAR buf[128];
    wsprintf(buf, TEXT("BPM: %d"), m_composition->beatsPerMinute());
    m_hBpm = CreateWindow(TEXT("STATIC"), buf, WS_CHILD | WS_VISIBLE | SS_LEFT | SS_NOPREFIX, Dialog::widthToPixels(4), Dialog::heightToPixels(2), Dialog::widthToPixels((width() / 2) - 8), Dialog::heightToPixels(8), hWnd(), 0, parent->hInstance(), 0);
    wsprintf(buf, TEXT("Signature: %d/%d"), m_composition->beatsPerMeasure(), m_composition->beatNoteType());
    m_hSignature = CreateWindow(TEXT("STATIC"), buf, WS_CHILD | WS_VISIBLE | SS_LEFT | SS_NOPREFIX, Dialog::widthToPixels(4), Dialog::heightToPixels(12), Dialog::widthToPixels((width() / 2) - 8), Dialog::heightToPixels(8), hWnd(), 0, parent->hInstance(), 0);
    MusicTime dummy;
    wsprintf(buf, TEXT("Position: "));
    dummy.toStringAsMeasures(buf + _tcslen(buf), 128 - _tcslen(buf), m_composition->beatsPerMinute(), m_composition->beatsPerMeasure(), m_composition->beatNoteType());
    m_hPos = CreateWindow(TEXT("STATIC"), buf, WS_CHILD | WS_VISIBLE | SS_LEFT | SS_NOPREFIX, Dialog::widthToPixels(width() / 2), Dialog::heightToPixels(2), Dialog::widthToPixels((width() / 2) - 8), Dialog::heightToPixels(8), hWnd(), 0, parent->hInstance(), 0);
}

CompositionInfoControl::~CompositionInfoControl() {
    DestroyWindow(m_hPos);
    DestroyWindow(m_hSignature);
    DestroyWindow(m_hBpm);
}

void CompositionInfoControl::updateSongPosition(const MusicTime &pos) throw() {
    TCHAR buf[128] = TEXT("Position: ");
    pos.toStringAsMeasures(buf + _tcslen(buf), 128 - _tcslen(buf), m_composition->beatsPerMinute(), m_composition->beatsPerMeasure(), m_composition->beatNoteType());
    SendMessage(m_hPos, WM_SETTEXT, 0, LPARAM(buf));
}

void CompositionInfoControl::paint(HDC hDc) const throw() {
}

void CompositionInfoControl::controlNotification(HWND hCtrl, WPARAM notification) throw() {
}

void CompositionInfoControl::click(unsigned int x, unsigned int y) throw() {
}
